package com.wufei.tastefor.utils;

import android.content.Context;

import com.lidroid.xutils.DbUtils;

/**
 * Created by wbcomputer on 2015/10/24.
 */
public class XutilsHelper {
    private static XutilsHelper helper = new XutilsHelper();
    private DbUtils dbUtils;
    private static Context context;
    private DbUtils.DaoConfig config;

    public static void init(Context context){
        XutilsHelper.context  = context;
    }

    private XutilsHelper() {
    }

    public static XutilsHelper getInstance() {
        return helper;
    }

    public DbUtils.DaoConfig getDaoConfig(){
        if (config==null){
            config = new DbUtils.DaoConfig(context);
            config.setDbDir(FileUtils.getDbFile(context).getAbsolutePath());
            config.setDbName(AppConfig.DB_NAME);
            config.setDbVersion(1);
            config.setDbUpgradeListener(new DbUtils.DbUpgradeListener() {
                @Override
                public void onUpgrade(DbUtils db, int oldVersion, int newVersion) {

                }
            });

        }

        return config;
    }
    public DbUtils getDbUtils() {
        if (dbUtils == null) {
            dbUtils = DbUtils.create(getDaoConfig());
        }
        return dbUtils;
    }


}
